package cn.xuewenbao.edu.mapper;

import cn.xuewenbao.edu.entity.LikeContent;
import cn.xuewenbao.edu.entity.vo.MyLikeContentVo;
import cn.xuewenbao.edu.entity.vo.MyLikeOrFavoriteContentVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 点赞表 Mapper 接口
 * </p>
 *
 * @author mafayu
 * @since 2021-04-21
 */
@Mapper
public interface LikeContentMapper extends BaseMapper<LikeContent> {

    @Select("SELECT title, cover, view_count " +
            "FROM ${tableName} " +
            "WHERE id = #{contentId} ")
    MyLikeOrFavoriteContentVo selectMyList(String contentId, String tableName);

//    @Select("SELECT l.content_id id, l.column_type ,l.user_id, a.title, a.cover, cd.like_count, cd.favorite_count, (SELECT COUNT(1) FROM `comment` c where c.contentId = l.content_id) comment_count, TRUE isLike, (SELECT COUNT(1) from favorite)>0 AS isFavorite  \n" +
//            "FROM like_content l\n" +
//            "LEFT JOIN column_data cd ON l.content_id = cd.content_id\n" +
//            "LEFT JOIN article a ON a.id = l.content_id\n" +
//            "WHERE l.user_id = #{userId}")
//    List<MyLikeContentVo> selectMyList(String userId, String columnType);

    @Select("SELECT ${fieldName}\n" +
            "FROM ${tableName}\n" +
            "WHERE id=#{contentId}")
    String getUserId(String contentId, String tableName, String fieldName);

    @Select("SELECT author_id \n" +
            "FROM journal_subject \n" +
            "WHERE id=#{contentId}")
    String getJournalUserId(String contentId);
}
